#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <iostream>
#include <iomanip>

int main(int argc, char* argv[])
{
	SDL_Init(SDL_INIT_EVERYTHING);

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	SDL_Surface* myTexture = IMG_Load("C:\\zms\\resources\\image\\Z-Box.png");
	if (myTexture == NULL)
	{
		std::cout << "Error Loading Texture" << std::endl;
	}
	else
	{
		std::cout << "Texture Loaded" << std::endl;
		std::cout << "  Height: " << myTexture->h << std::endl;
		std::cout << "  Width: " << myTexture->w << std::endl;
		std::cout << "  Bytes Per Pixel: " << (int)(myTexture->format->BytesPerPixel) << std::endl;
		std::cout << "  Red Mask: " << std::setfill('0') << std::setw(8) << std::hex << myTexture->format->Rmask << std::endl;
		std::cout << "  Green Mask: " << std::setfill('0') << std::setw(8) << std::hex << myTexture->format->Gmask << std::endl;
		std::cout << "  Blue Mask: " << std::setfill('0') << std::setw(8) << std::hex << myTexture->format->Bmask << std::endl;
	}

	SDL_Surface* mySurface = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL);
	if (mySurface == NULL)
	{
		std::cout << "Error Initializing Video Mode" << std::endl;
	}
	else
	{
		std::cout << "Initialized Video Mode" << std::endl;
	}

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glOrtho(0.0f, 640.0f, 0.0f, 480.0f, 0.0f, 1.0f);
	glViewport(0, 0, 640, 480);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_QUADS);
		glVertex2f(160.0f, 120.0f);
		glVertex2f(480.0f, 120.0f);
		glVertex2f(480.0f, 360.0f);
		glVertex2f(160.0f, 360.0f);
	glEnd();

	SDL_GL_SwapBuffers();

	SDL_Delay(1500);

	return 0;
}
